import { NextResponse } from 'next/server';
import articlesModule from '@/modules/article';
import templates from '@/template/articles/config'
import {TIP_TAP_DEFAULT} from '@/config/settings'

export async function GET(request, { params }) {
  const { id } = await params;
  const codeMap = { 0: '获取成功', 1: '内容为空' };
  const article = await articlesModule.getById(Number(id));
  if (!article) { return NextResponse.json({ code: 1, codeMap, message: 'No articles found' }); }
  const content = article.content ? JSON.parse(article.content) : TIP_TAP_DEFAULT;
  return NextResponse.json({ code: 0, codeMap, message: 'Success', data: { ...article, templates, content } });
}